<template>
  <lc-chart-pie
    ref="pieRef"
    :options="pieOptions"
    :map-options="pieMapOptions"
    :data="pieData"
    style="--height: 300px"
  ></lc-chart-pie>
</template>

<script setup>
import { ref } from "vue";

import { request } from "@/apis/request";
defineOptions({
  name: "Pie",
});

const pieRef = ref(null);
const pieData = ref([]);
const pieMapOptions = ref({});
const pieOptions = ref({
  title: { text: "", top: 10, left: 10 },
  legend: { right: 10, top: 10 },
  tooltip: { trigger: "item", formatter: "" },
  grid: {
    left: "6%",
    top: "20%",
    right: "5%",
    bottom: "10%",
    containLabel: true,
  },
  color: [
    "rgba(62, 115, 241, 1)",
    "rgba(72, 192, 179, 1)",
    "rgba(123, 185, 44, 1)",
    "rgba(254, 216, 49, 1)",
    "rgba(243, 113, 50, 1)",
    "rgba(240, 54, 62, 1)",
    "rgba(250, 97, 102, 1)",
    "rgba(151, 96, 226, 1)",
  ],
  series: [
    {
      type: "pie",
      radius: "50%",
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: "rgba(0, 0, 0, 0.5)",
        },
      },
    },
  ],
});

const getPieData = async () => {
  try {
    let params = { url: "", method: "get", params: {} };
    const res = await request(params);
    if (res) {
      pieData.value = res.data || [];
    }
  } catch (e) {
    console.error("获取数据出错: " + e);
  }
};
getPieData();
</script>
